package com.yanqu.road.logic.activity.foxcard.game.effect;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardShowType;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 计分前,吸收打出的手牌,增强/蜡封效果，加效果。
 * buffsort|加筹码基础值|乘筹码基础值|加倍率基础值|乘倍率基础值|金币基础值
 */
public class FoxCardEffect26 extends FoxCardEffectBase {
    @Override
    protected void effectHandle(FoxCardGameLogic gameLogic, FoxHandCard handCard) {
        if (triggerType == eFoxCardTriggerType.ADD && handCard == null) {
            effectCard.setEffectValues(Collections.singletonList(0l));
        } else if (triggerType == eFoxCardTriggerType.BEFORE_SCORE) {
            int buffSort = Integer.valueOf(effectConfig.getParamsList().get(0));

            List<FoxBaseCard> buffChangeCards = new ArrayList<>();
            for (FoxHandCard showHandCard : gameLogic.getShowHandCards()) {
                if (buffSort == 1) {//增强效果
                    if (showHandCard.getReinforceEffect() > 0) {
                        showHandCard.setReinforceEffect(0);
                        buffChangeCards.add(showHandCard);
                    }
                } else if (buffSort == 3) {//蜡封效果
                    if (showHandCard.getSealEffect() > 0) {
                        showHandCard.setSealEffect(0);
                        buffChangeCards.add(showHandCard);
                    }
                }
            }
            List<FoxBaseCard> settleCards = Collections.singletonList(effectCard);
            if (!buffChangeCards.isEmpty()) {
                FoxCardShowInfo showInfo = gameLogic.newFoxShow(buffSort == 1 ? eFoxCardShowType.REINFORCE_EFFECT.getValue() : eFoxCardShowType.SEAL_EFFECT.getValue());
                showInfo.setSettleCards(settleCards);
                showInfo.setTriggerCards(buffChangeCards);
                showInfo.setShowValue(0);
            }

            int totalTimes = buffChangeCards.size();
            long newTimes = effectCard.getEffectValues().get(0) + totalTimes;
            effectCard.getEffectValues().set(0, newTimes);
        } else if (triggerType == eFoxCardTriggerType.AFTER_SCORE) {
            int totalTimes = effectCard.getEffectValues().get(0).intValue();

            int addBaseScore = Integer.valueOf(effectConfig.getParamsList().get(1)) + totalTimes * Integer.valueOf(effectConfig.getUpgradeParamsList().get(0));
            int addBaseScoreMulti = Integer.valueOf(effectConfig.getParamsList().get(2)) + totalTimes * Integer.valueOf(effectConfig.getUpgradeParamsList().get(1));
            int addBaseMulti = Integer.valueOf(effectConfig.getParamsList().get(3)) + totalTimes * Integer.valueOf(effectConfig.getUpgradeParamsList().get(2));
            int addBaseMultiMulti = Integer.valueOf(effectConfig.getParamsList().get(4)) + totalTimes * Integer.valueOf(effectConfig.getUpgradeParamsList().get(3));
            int goldChange = Integer.valueOf(effectConfig.getParamsList().get(5)) + totalTimes * Integer.valueOf(effectConfig.getUpgradeParamsList().get(4));

            List<FoxBaseCard> foxEffectCards = Collections.singletonList(effectCard);
            gameLogic.addBaseScore(addBaseScore, foxEffectCards, null); //加基础筹码
            gameLogic.addBaseScoreMulti(addBaseScoreMulti, foxEffectCards, null); //当前基础筹码乘算
            gameLogic.addBaseMulti(addBaseMulti, foxEffectCards, null); //加基础倍率
            gameLogic.addBaseMultiMulti(addBaseMultiMulti, foxEffectCards, null); //当前基础倍率乘算
            gameLogic.goldChange(goldChange, foxEffectCards, null, triggerType); //加金币
        }
    }
}
